<style scoped>
.text {
  font-size: 14px;
}

.item {
  margin-bottom: 18px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both;
}

.box-card {
  width: 380px;
}
</style>
<template>
  <div class="app-container" style="height: 900px">
    <amap :zoom="7" >
      <amap-marker
        v-for="(d, index) in dataList"
        :key="d.address"
        :position="[d.lng, d.lat]"
        :index="index"
        :icon="d.icon"
        :label="{
          content: '温度:' + d.wendu + '°',
           offset:[40, 10]
        }"
        @click="showWindo(d)"
      />
     
    </amap>
    <el-dialog :title="focusData.address+'  主要污染物：'+focusData.wuran" :visible.sync="open"  >

          <el-row>
             <el-col :span="8"> {{ "PM2.5: " + focusData.pm25 }}</el-col>
            <el-col :span="8">{{ "PM10: " + focusData.pm10 }}</el-col>
            <el-col :span="8">{{ "TSP: " + focusData.tsp }}</el-col>
          </el-row>
          <el-row>
             <el-col :span="8"> {{ "噪声: " + focusData.zaosheng }}</el-col>
            <el-col :span="8"> {{ "温度: " + focusData.wendu }}</el-col>
            <el-col :span="8">{{ "湿度: " + focusData.shidu }}</el-col>
          </el-row>
           <el-row>
             <el-col :span="8">{{ "风速: " + focusData.fengsu }}</el-col>
            <el-col :span="8">{{ "风向: " + focusData.fengxiang }}</el-col>
            <el-col :span="8">{{ "气压: " + focusData.qiya }}</el-col>
          </el-row>
  
      </el-dialog>
  </div>
</template>
<script>
import redIcon from "@/assets/map/red.svg";
import green from "@/assets/map/green.svg";
import origin from "@/assets/map/origin.svg";
import purpol from "@/assets/map/purpol.svg";
import yello from "@/assets/map/yello.svg";
import deepRed from "@/assets/map/deep-red.svg";
import { listData } from "@/api/system/data";
import { listAddress } from "@/api/system/address";
import { maxlist } from "@/api/system/data";
export default {
  name: "Data",
  data() {
    return {
      redIcon,
      green,
      origin,
      purpol,
      yello,
      deepRed,
      // 遮罩层
      loading: true,
      focusData: {address: "上海",
aqi: "250",
createBy: "admin",
createTime: "2020-11-07 00:06:24",
dataId: 7,
dataScope: null,
fengsu: "3",
fengxiang: "4",
jibie: "高度污染",
lat: "31.224939",
lng: "121.477323",
params: {},
pm10: "10",
pm25: "10",
qiya: "4",
remark: null,
searchValue: null,
shidu: "23",
tsp: "2",
updateBy: null,
updateTime: null,
wendu: "2",
wuran: "PM2.5",
visible:false,
zaosheng: "2"},
      showInfoWindow: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 监测数据表格数据
      dataList: [],
      addressOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        addressId: undefined,
        address: undefined,
        lat: undefined,
        lng: undefined,
        wuran: undefined,
        jibie: undefined,
        aqi: undefined,
        pm25: undefined,
        pm10: undefined,
        tsp: undefined,
        zaosheng: undefined,
        wendu: undefined,
        shidu: undefined,
        fengsu: undefined,
        fengxiang: undefined,
        qiya: undefined,
        createTime: undefined,
        
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
    listAddress().then((res) => {
      this.addressOptions = res.rows;
    });
  },
  methods: {
    showWindo(d) {
     
      // this.open = true
      // this.focusData = d;
      this.$router.push({path:"/data/showDetail",query:d})
    },
    hideInfoWindow() {
      console.log( this.focusData.visible)
      this.open = false
    },
    /** 查询监测数据列表 */
    getList() {
      this.loading = true;
      maxlist(this.queryParams).then((response) => {
        this.dataList = response.data;
    
        this.dataList.forEach((e) => {
          e.visible = false
          if (e.aqi < 50) {
            e.icon = green;
          } else if (e.aqi < 100) {
            e.icon = yello;
          } else if (e.aqi < 150) {
            e.icon = origin;
          } else if (e.aqi < 200) {
            e.icon = redIcon;
          } else if (e.aqi < 300) {
            e.icon = purpol;
          } else {
            e.icon = deepRed;
          }
        });
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        dataId: undefined,
        address: undefined,
        lat: undefined,
        lng: undefined,
        wuran: undefined,
        jibie: undefined,
        aqi: undefined,
        pm25: undefined,
        pm10: undefined,
        tsp: undefined,
        zaosheng: undefined,
        wendu: undefined,
        shidu: undefined,
        fengsu: undefined,
        fengxiang: undefined,
        qiya: undefined,
        createBy: undefined,
        createTime: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.dataId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加监测数据";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const dataId = row.dataId || this.ids;
      getData(dataId).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改监测数据";
      });
    },
    /** 提交按钮 */
    submitForm: function () {
      this.form.addressId;
      for (let i in this.addressOptions) {
        if (this.addressOptions[i].addressId == this.form.addressId) {
          this.form.address = this.addressOptions[i].addName;
          this.form.lng = this.addressOptions[i].lng;
          this.form.lat = this.addressOptions[i].lat;
        }
      }
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.dataId != undefined) {
            updateData(this.form).then((response) => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          } else {
            addData(this.form).then((response) => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const dataIds = row.dataId || this.ids;
      this.$confirm(
        '是否确认删除监测数据编号为"' + dataIds + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delData(dataIds);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(function () {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有监测数据数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return exportData(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
        })
        .catch(function () {});
    },
  },
};
</script>